﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows.Data;

namespace SanctusSoftware.CcliSongSelectImporter
{
    public class BooleanVisibilityConverter : IValueConverter
    {



        public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
        {

            bool boolValue = false;

            if (value is bool)
            {
                boolValue = (bool)value;    
            }
            else if (value is bool? && ((bool?)value).HasValue)
            {
                boolValue = ((bool?)value).Value;
            }

            // Parameter is for inverting
            bool parameterTemp;
            if (parameter != null && bool.TryParse(parameter.ToString(), out parameterTemp))
            {
                if (parameterTemp)
                {
                    boolValue = !boolValue;
                }
            }

            return boolValue ? System.Windows.Visibility.Visible : System.Windows.Visibility.Collapsed;
            
        }

        public object ConvertBack(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
        {
            throw new NotImplementedException();
        }
    }
}
